/*
 * MainWindow.java
 *
 * Created on September 5, 2006, 8:41 AM
 */
package smfbackup;

import java.awt.AWTException;
import java.awt.Desktop;
import java.awt.Frame;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;

import org.apache.log4j.Logger;

import smfbackup.conf.Configuration;
import smfbackup.conf.Forum;
import smfbackup.run.Scheduler;

/**
 *
 * @author  Iulian
 */
public class MainWindow extends JFrame implements ActionListener {

    private static String VERSION = "1.3.5";

    private String rootName = "Forums";
    LookAndFeelInfo lf[];
    private Scheduler sch;
    // Commons Logger wrapper setup
    private Logger log = Logger.getLogger(MainWindow.class);
    // Activation/Deactivation issues
    private Window lastDialogOnScreen;
    // is windows ?
    private static boolean isWindows = System.getProperty("os.name").startsWith("Win");
    // tray menu
    Object tray = null;
    PopupMenu menu;

    /** Creates new form MainWindow */
    public MainWindow() {
        initComponents();

        loadConfiguration();
    }

    private void loadConfiguration() {
        Configuration.loadConfiguration();

        Main.setLoggingLevel(Configuration.getLoggingLevel());

        repopulateForumsList(0);
        repopulateAboutDialog();
        regenerateLookAndFeelDropdownItems();
        repopulateForumsTree();

        try {
            initSystemTray();
        } catch (AWTException awtex) {
            ErrorHandler.showError("Unable to set the System Tray.", awtex);
        }

        propagateUIChanges(Configuration.getLookAndFeel());
        loadScheduler();

        // set divider location
        if (Configuration.getDividerLocation() != null) {
            displaySplitPane.setDividerLocation(Integer.parseInt(Configuration.getDividerLocation()));
            // select the first forum in list (doesn't do anything if empty list)
        }
        clickOnForum(0);
    }

    public boolean isStartMinimized() {
        return (Configuration.getStartupOption() != null && Configuration.getStartupOption().toLowerCase().startsWith("minimized"));
    }

    private void initSystemTray() throws AWTException {
        String toolTip = "SMFBackup " + VERSION;
        MenuItem menuItem;
        TrayIcon ti;

        if (Integer.parseInt(System.getProperty("java.version").substring(2, 3)) >= 5) {
            System.setProperty("javax.swing.adjustPopupLocationToFit", "false");
        }
        menu = new PopupMenu("SMFBackup Menu");
        menuItem = new MenuItem("Show Window");
        menuItem.addActionListener(this);
        menu.add(menuItem);
        menu.addSeparator();
        menuItem = new MenuItem("Quit");
        menuItem.addActionListener(this);
        menu.add(menuItem);

        ImageIcon i = new ImageIcon(MainWindow.class.getResource("/img/AppIconSmall.gif"));
        ti = new TrayIcon(i.getImage(), toolTip, menu);

        ti.setImageAutoSize(true);
        ti.addActionListener(this);

        if (tray == null) {
            tray = SystemTray.getSystemTray();
        }

        ((SystemTray) tray).add(ti);
    }

    private SpinnerNumberModel getRepeatAtJSpinnerModel() {
        SpinnerNumberModel model;
        model = new SpinnerNumberModel(new Integer(24), new Integer(1), new Integer(72), new Integer(1));
        return model;
    }

    private SpinnerDateModel getStartAtJSpinnerModel() {
        SpinnerDateModel dateModel;

        dateModel = new SpinnerDateModel(new Date(), null, null, Calendar.MINUTE);
        return dateModel;
    }

    private JSpinner.DateEditor getStartAtJSpinnerEditor() {
        return new JSpinner.DateEditor(startAtJSpinner, "HH:mm");
    }

    /*
     * Makes jspinner render a date (can't do it from NetBeans)
     */
    private void fixJSpinner() {

        startAtJSpinner.addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent e) {
                JSpinner source = (JSpinner) e.getSource();
                try {
                    source.commitEdit();
                } catch (Exception ex) {
                    log.error(ex);
                }
            }
        });
    }

    /* must be started after the configuration has been loaded */
    private void loadScheduler() {
        // (new TestLogging(this)).start();
        sch = new Scheduler(this);
        sch.start();
    }

    private void repopulateForumsTree() {
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Forums");

        for (int i = 0; i < Configuration.getForumsDefined().size(); i++) {
            DefaultMutableTreeNode node = new DefaultMutableTreeNode(Configuration.getForumsDefined().elementAt(i));
            root.add(node);
        }

        DefaultTreeModel model = (DefaultTreeModel) forumsTree.getModel();
        model.setRoot(root);
        model.reload();
    }

    private void propagateUIChanges(String uiClassName) {
        try {

            if (uiClassName == null) {
                return;
            }
            UIManager.setLookAndFeel(uiClassName);

            SwingUtilities.updateComponentTreeUI(lookAndFeelDialog);
            SwingUtilities.updateComponentTreeUI(aboutDialog);
            SwingUtilities.updateComponentTreeUI(manageForumsDialog);
            SwingUtilities.updateComponentTreeUI(forumsPopupMenu);
            SwingUtilities.updateComponentTreeUI(settingsDialog);
            SwingUtilities.updateComponentTreeUI(jTipsTricksDialog);
            SwingUtilities.updateComponentTreeUI(this);

        } catch (Throwable t) {
            ErrorHandler.showError("Unable to propagate UI changes.", t);
        }

    }

    private void repopulateAboutDialog() {
        String ack =
                "Runtime environment:\n" +
                "java.home=" + System.getProperty("java.home") + "\n\n" +
                "SMF Backup uses the following libraries:\n\n" +
                "Jakarta HttpClient (Apache Open Source license) available at\n" +
                "http://jakarta.apache.org/commons/httpclient/\n\n" +
                "Jericho HTML Parser (LGPL license) available at\n" +
                "http://freshmeat.net/projects/jerichohtml/\n\n" +
                "Liquid Look and Feel available at\n" +
                "https://liquidlnf.dev.java.net/\n\n" +
                "Silk Icons available at\n" +
                "http://www.famfamfam.com/lab/icons/silk/\n\n" +
                "JDesktop Integration Components available at\n" +
                "https://jdic.dev.java.net/" ;

        versionLabel.setText(versionLabel.getText() + " " + VERSION);

        ackTextArea.setText(ack);
    }

    private void regenerateLookAndFeelDropdownItems() {

        lf = UIManager.getInstalledLookAndFeels();

        for (int i = 0; i < lf.length; i++) {
            lookAndFeelComboBox.addItem(lf[i].getName());

            if (lf[i].getClassName().equals(Configuration.getLookAndFeel())) {
                lookAndFeelComboBox.setSelectedIndex(i);
            }
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        manageForumsDialog = new javax.swing.JDialog();
        jScrollPane1 = new javax.swing.JScrollPane();
        forumsDefinedList = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        forumNameTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        forumURLTextField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        forumVersionDropDown = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        forumAdminUserNameTextField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        updateForumButton = new javax.swing.JButton();
        forumAdminPasswordTextField = new javax.swing.JPasswordField();
        forumDoBackupAtStartCheckBox = new javax.swing.JCheckBox();
        forumDisableBackupCheckBox = new javax.swing.JCheckBox();
        jLabel7 = new javax.swing.JLabel();
        intervalComboBox = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        startAtJSpinner = new javax.swing.JSpinner();
        repeatAtJSpinner = new javax.swing.JSpinner();
        jLabel23 = new javax.swing.JLabel();
        forumDoCompression = new javax.swing.JCheckBox();
        addNewForumButton = new javax.swing.JButton();
        removeForumButton = new javax.swing.JButton();
        closeManageForumsButton = new javax.swing.JButton();
        aboutDialog = new javax.swing.JDialog();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        ackTextArea = new javax.swing.JTextArea();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        closeAboutDialogButton = new javax.swing.JButton();
        versionLabel = new javax.swing.JLabel();
        jVisitHomePage = new javax.swing.JButton();
        lookAndFeelDialog = new javax.swing.JDialog();
        lookAndFeelComboBox = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        cancelChangeLFButton = new javax.swing.JButton();
        okChangeLFButton = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel20 = new javax.swing.JLabel();
        forumsPopupMenu = new javax.swing.JPopupMenu();
        runBackupNowMenuItem = new javax.swing.JMenuItem();
        stopBackupNowMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        manageForumMenuItem = new javax.swing.JMenuItem();
        settingsDialog = new javax.swing.JDialog();
        proxyActiveCheckBox = new javax.swing.JCheckBox();
        jPanel2 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        proxyServerNameTextField = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        proxyServerPortTextField = new javax.swing.JTextField();
        cancelSettingsButton = new javax.swing.JButton();
        okSettingsButton = new javax.swing.JButton();
        jLabel18 = new javax.swing.JLabel();
        backupDirectoryTextField = new javax.swing.JTextField();
        browseButton = new javax.swing.JButton();
        jLabel19 = new javax.swing.JLabel();
        loggingLevelComboBox = new javax.swing.JComboBox();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        startupComboBox = new javax.swing.JComboBox();
        jLabel24 = new javax.swing.JLabel();
        userAgentTextField = new javax.swing.JTextField();
        jTipsTricksDialog = new javax.swing.JDialog();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTipsTricksEditorPane = new javax.swing.JEditorPane();
        jOkTipsTricks = new javax.swing.JButton();
        jToolBar1 = new javax.swing.JToolBar();
        manageForumsButton = new javax.swing.JButton();
        lookAndFeelButton = new javax.swing.JButton();
        settingsButton = new javax.swing.JButton();
        stopAllBackupsButton = new javax.swing.JButton();
        displaySplitPane = new javax.swing.JSplitPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        forumsTree = new javax.swing.JTree();
        jScrollPane5 = new javax.swing.JScrollPane();
        logTextArea = new javax.swing.JTextArea();
        jStatusBar = new javax.swing.JToolBar();
        jStatusLabel = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        exitMenuItem = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        manageForumsMenuItem = new javax.swing.JMenuItem();
        lookandfeelMenuItem = new javax.swing.JMenuItem();
        settingsMenuItem = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jTipsTricksMenuItem = new javax.swing.JMenuItem();
        jChangeLogMenuItem = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        aboutMenuItem = new javax.swing.JMenuItem();

        manageForumsDialog.setTitle("Manage Forums");
        manageForumsDialog.setModal(true);

        forumsDefinedList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        forumsDefinedList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                forumsDefinedListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(forumsDefinedList);

        jLabel1.setDisplayedMnemonic('o');
        jLabel1.setLabelFor(forumsDefinedList);
        jLabel1.setText("Forums:");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Settings"));

        jLabel2.setDisplayedMnemonic('N');
        jLabel2.setLabelFor(forumNameTextField);
        jLabel2.setText("Name:");

        forumNameTextField.setText("jTextField1");

        jLabel3.setDisplayedMnemonic('L');
        jLabel3.setLabelFor(forumURLTextField);
        jLabel3.setText("Forum URL:");

        forumURLTextField.setText("jTextField2");

        jLabel4.setDisplayedMnemonic('V');
        jLabel4.setLabelFor(forumVersionDropDown);
        jLabel4.setText("SMF Version:");

        forumVersionDropDown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SMF 1.0.X", "SMF 1.1.X", "SMF 2.0 Beta3", "SMF 2.0 RC1.X", "SMF 2.0 RC2.X" }));

        jLabel5.setDisplayedMnemonic('U');
        jLabel5.setLabelFor(forumAdminUserNameTextField);
        jLabel5.setText("Admin User Name:");

        forumAdminUserNameTextField.setText("jTextField3");

        jLabel6.setDisplayedMnemonic('P');
        jLabel6.setLabelFor(forumAdminPasswordTextField);
        jLabel6.setText("Admin Password:");

        updateForumButton.setMnemonic('p');
        updateForumButton.setText("Update");
        updateForumButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateForumButtonActionPerformed(evt);
            }
        });

        forumAdminPasswordTextField.setText("jPasswordField1");

        forumDoBackupAtStartCheckBox.setMnemonic('B');
        forumDoBackupAtStartCheckBox.setText("Do Backup When Program Starts");
        forumDoBackupAtStartCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        forumDoBackupAtStartCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));

        forumDisableBackupCheckBox.setMnemonic('D');
        forumDisableBackupCheckBox.setText("Disable Backup For This Forum");
        forumDisableBackupCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        forumDisableBackupCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jLabel7.setDisplayedMnemonic('S');
        jLabel7.setLabelFor(intervalComboBox);
        jLabel7.setText("Schedule:");

        intervalComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Every Day" }));

        jLabel8.setDisplayedMnemonic('A');
        jLabel8.setLabelFor(startAtJSpinner);
        jLabel8.setText("At:");

        jLabel9.setDisplayedMnemonic('R');
        jLabel9.setText("Repeat every:");

        jLabel10.setText("hour(s)");

        startAtJSpinner.setModel(getStartAtJSpinnerModel());
        startAtJSpinner.setToolTipText("24 hours format.");
        startAtJSpinner.setEditor(getStartAtJSpinnerEditor());

        repeatAtJSpinner.setModel(getRepeatAtJSpinnerModel());

        jLabel23.setText("Compress:");

        forumDoCompression.setSelected(true);
        forumDoCompression.setToolTipText("Uncheck if the forum runs out of memory while compressing a big database.");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                        .add(updateForumButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
                    .add(forumDoBackupAtStartCheckBox)
                    .add(forumDisableBackupCheckBox)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel5)
                            .add(jLabel6)
                            .add(jLabel4)
                            .add(jLabel2)
                            .add(jLabel3)
                            .add(jLabel7)
                            .add(jLabel23))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(forumDoCompression)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(forumNameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, forumURLTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE)
                            .add(forumVersionDropDown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, forumAdminUserNameTextField)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, forumAdminPasswordTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE))
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(intervalComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(15, 15, 15)
                                .add(jLabel8)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(startAtJSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 55, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel9)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(repeatAtJSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(4, 4, 4)
                                .add(jLabel10)))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(forumNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(forumURLTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(forumVersionDropDown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(forumAdminUserNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(forumAdminPasswordTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(intervalComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel8)
                    .add(jLabel9)
                    .add(jLabel10)
                    .add(startAtJSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(repeatAtJSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(forumDoCompression)
                    .add(jLabel23))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 37, Short.MAX_VALUE)
                .add(forumDoBackupAtStartCheckBox)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(forumDisableBackupCheckBox)
                .add(10, 10, 10)
                .add(updateForumButton)
                .addContainerGap())
        );

        jPanel1Layout.linkSize(new java.awt.Component[] {forumDoCompression, jLabel23}, org.jdesktop.layout.GroupLayout.VERTICAL);

        addNewForumButton.setMnemonic('F');
        addNewForumButton.setText("Add Forum");
        addNewForumButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addNewForumButtonActionPerformed(evt);
            }
        });

        removeForumButton.setMnemonic('m');
        removeForumButton.setText("Remove");
        removeForumButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeForumButtonActionPerformed(evt);
            }
        });

        closeManageForumsButton.setMnemonic('C');
        closeManageForumsButton.setText("Close");
        closeManageForumsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeManageForumsButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout manageForumsDialogLayout = new org.jdesktop.layout.GroupLayout(manageForumsDialog.getContentPane());
        manageForumsDialog.getContentPane().setLayout(manageForumsDialogLayout);
        manageForumsDialogLayout.setHorizontalGroup(
            manageForumsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(manageForumsDialogLayout.createSequentialGroup()
                .addContainerGap()
                .add(manageForumsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(manageForumsDialogLayout.createSequentialGroup()
                        .add(manageForumsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, manageForumsDialogLayout.createSequentialGroup()
                                .add(addNewForumButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(removeForumButton))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 169, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(manageForumsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(closeManageForumsButton))))
                .addContainerGap())
        );
        manageForumsDialogLayout.setVerticalGroup(
            manageForumsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, manageForumsDialogLayout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(manageForumsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(manageForumsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(addNewForumButton)
                    .add(closeManageForumsButton)
                    .add(removeForumButton))
                .addContainerGap())
        );

        aboutDialog.setTitle("About...");
        aboutDialog.setModal(true);

        jLabel11.setText("Copyright:");

        ackTextArea.setColumns(20);
        ackTextArea.setEditable(false);
        ackTextArea.setFont(new java.awt.Font("Tahoma", 0, 12));
        ackTextArea.setLineWrap(true);
        ackTextArea.setRows(5);
        jScrollPane2.setViewportView(ackTextArea);

        jLabel12.setText("License:");

        jLabel13.setText("Iulian Virtejanu, 2006 - 2011");

        jLabel14.setText("GPL");

        closeAboutDialogButton.setMnemonic('C');
        closeAboutDialogButton.setText("Close");
        closeAboutDialogButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeAboutDialogButtonActionPerformed(evt);
            }
        });

        versionLabel.setFont(new java.awt.Font("Tahoma", 1, 14));
        versionLabel.setText("SMF Backup");

        jVisitHomePage.setText("Visit Home Page / Donate");
        jVisitHomePage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jVisitHomePageActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout aboutDialogLayout = new org.jdesktop.layout.GroupLayout(aboutDialog.getContentPane());
        aboutDialog.getContentPane().setLayout(aboutDialogLayout);
        aboutDialogLayout.setHorizontalGroup(
            aboutDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(aboutDialogLayout.createSequentialGroup()
                .addContainerGap()
                .add(aboutDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, aboutDialogLayout.createSequentialGroup()
                        .add(jVisitHomePage)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 276, Short.MAX_VALUE)
                        .add(closeAboutDialogButton)
                        .addContainerGap())
                    .add(aboutDialogLayout.createSequentialGroup()
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 488, Short.MAX_VALUE)
                        .addContainerGap())
                    .add(aboutDialogLayout.createSequentialGroup()
                        .add(aboutDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(versionLabel)
                            .add(aboutDialogLayout.createSequentialGroup()
                                .add(jLabel12)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel14))
                            .add(aboutDialogLayout.createSequentialGroup()
                                .add(jLabel11)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel13)))
                        .add(304, 304, 304))))
        );
        aboutDialogLayout.setVerticalGroup(
            aboutDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(aboutDialogLayout.createSequentialGroup()
                .addContainerGap()
                .add(versionLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 23, Short.MAX_VALUE)
                .add(aboutDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel11)
                    .add(jLabel13))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(aboutDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel12)
                    .add(jLabel14))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 161, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(aboutDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(closeAboutDialogButton)
                    .add(jVisitHomePage))
                .addContainerGap())
        );

        lookAndFeelDialog.setTitle("Java Look and Feel");
        lookAndFeelDialog.setModal(true);

        jLabel15.setDisplayedMnemonic('L');
        jLabel15.setLabelFor(lookAndFeelComboBox);
        jLabel15.setText("Look and Feel:");

        cancelChangeLFButton.setMnemonic('C');
        cancelChangeLFButton.setText("Cancel");
        cancelChangeLFButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelChangeLFButtonActionPerformed(evt);
            }
        });

        okChangeLFButton.setMnemonic('O');
        okChangeLFButton.setText("Ok");
        okChangeLFButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okChangeLFButtonActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(10);
        jTextArea1.setEditable(false);
        jTextArea1.setFont(new java.awt.Font("Arial", 0, 10));
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setText("For better looking results, please restart the application after selecting the desired look and feel. Sun recommands that setting the look and feel of an application to be design/startup preference instead of a runtime option.");
        jTextArea1.setWrapStyleWord(true);
        jScrollPane4.setViewportView(jTextArea1);

        jLabel20.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/exclamation.gif"))); // NOI18N
        jLabel20.setOpaque(true);

        org.jdesktop.layout.GroupLayout lookAndFeelDialogLayout = new org.jdesktop.layout.GroupLayout(lookAndFeelDialog.getContentPane());
        lookAndFeelDialog.getContentPane().setLayout(lookAndFeelDialogLayout);
        lookAndFeelDialogLayout.setHorizontalGroup(
            lookAndFeelDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(lookAndFeelDialogLayout.createSequentialGroup()
                .addContainerGap()
                .add(lookAndFeelDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, lookAndFeelDialogLayout.createSequentialGroup()
                        .add(lookAndFeelDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel20)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, lookAndFeelDialogLayout.createSequentialGroup()
                                .add(jLabel15)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(lookAndFeelComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 320, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, lookAndFeelDialogLayout.createSequentialGroup()
                        .add(okChangeLFButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cancelChangeLFButton)
                        .add(9, 9, 9))))
        );
        lookAndFeelDialogLayout.setVerticalGroup(
            lookAndFeelDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(lookAndFeelDialogLayout.createSequentialGroup()
                .addContainerGap()
                .add(lookAndFeelDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel15)
                    .add(lookAndFeelComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel20)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(lookAndFeelDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(okChangeLFButton)
                    .add(cancelChangeLFButton))
                .addContainerGap())
        );

        runBackupNowMenuItem.setText("Run Backup Now");
        runBackupNowMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                runBackupNowMenuItemActionPerformed(evt);
            }
        });
        forumsPopupMenu.add(runBackupNowMenuItem);

        stopBackupNowMenuItem.setText("Stop Backup");
        stopBackupNowMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopBackupNowMenuItemActionPerformed(evt);
            }
        });
        forumsPopupMenu.add(stopBackupNowMenuItem);
        forumsPopupMenu.add(jSeparator1);

        manageForumMenuItem.setText("Manage forum...");
        manageForumMenuItem.setToolTipText("Click to manage settings of this forum.");
        manageForumMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                manageForumMenuItemActionPerformed(evt);
            }
        });
        forumsPopupMenu.add(manageForumMenuItem);

        settingsDialog.setTitle("Proxy Settings");
        settingsDialog.setModal(true);

        proxyActiveCheckBox.setMnemonic('E');
        proxyActiveCheckBox.setText("Enable HTTP Proxy");
        proxyActiveCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        proxyActiveCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
        proxyActiveCheckBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                proxyActiveCheckBoxItemStateChanged(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("HTTP Proxy"));
        jPanel2.setEnabled(false);

        jLabel16.setDisplayedMnemonic('N');
        jLabel16.setLabelFor(proxyServerNameTextField);
        jLabel16.setText("Server Name:");

        jLabel17.setDisplayedMnemonic('P');
        jLabel17.setLabelFor(proxyServerPortTextField);
        jLabel17.setText("Server Port:");

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel16)
                    .add(jLabel17))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(proxyServerNameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
                    .add(proxyServerPortTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 68, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel16)
                    .add(proxyServerNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel17)
                    .add(proxyServerPortTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        cancelSettingsButton.setMnemonic('C');
        cancelSettingsButton.setText("Cancel");
        cancelSettingsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelSettingsButtonActionPerformed(evt);
            }
        });

        okSettingsButton.setMnemonic('O');
        okSettingsButton.setText("Ok");
        okSettingsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okSettingsButtonActionPerformed(evt);
            }
        });

        jLabel18.setDisplayedMnemonic('B');
        jLabel18.setLabelFor(backupDirectoryTextField);
        jLabel18.setText("Backup Directory:");

        backupDirectoryTextField.setText("jTextField1");

        browseButton.setMnemonic('.');
        browseButton.setText("...");
        browseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseButtonActionPerformed(evt);
            }
        });

        jLabel19.setDisplayedMnemonic('L');
        jLabel19.setLabelFor(loggingLevelComboBox);
        jLabel19.setText("Logging Level:");

        loggingLevelComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Debug", "Only Severe" }));

        jLabel21.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/exclamation.gif"))); // NOI18N
        jLabel21.setText("Debug creates HUGE log files.");

        jLabel22.setText("Start up:");

        startupComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Normal", "Minimized to Tray" }));

        jLabel24.setText("User Agent:");

        org.jdesktop.layout.GroupLayout settingsDialogLayout = new org.jdesktop.layout.GroupLayout(settingsDialog.getContentPane());
        settingsDialog.getContentPane().setLayout(settingsDialogLayout);
        settingsDialogLayout.setHorizontalGroup(
            settingsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(settingsDialogLayout.createSequentialGroup()
                .addContainerGap()
                .add(settingsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, settingsDialogLayout.createSequentialGroup()
                        .add(okSettingsButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cancelSettingsButton))
                    .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(proxyActiveCheckBox)
                    .add(settingsDialogLayout.createSequentialGroup()
                        .add(settingsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel18)
                            .add(jLabel19)
                            .add(jLabel22)
                            .add(jLabel24))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(settingsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(startupComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(settingsDialogLayout.createSequentialGroup()
                                .add(loggingLevelComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel21))
                            .add(settingsDialogLayout.createSequentialGroup()
                                .add(backupDirectoryTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(browseButton))
                            .add(userAgentTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE))))
                .addContainerGap())
        );
        settingsDialogLayout.setVerticalGroup(
            settingsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(settingsDialogLayout.createSequentialGroup()
                .addContainerGap()
                .add(settingsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel18)
                    .add(browseButton)
                    .add(backupDirectoryTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(settingsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(loggingLevelComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel19)
                    .add(jLabel21))
                .add(8, 8, 8)
                .add(settingsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(startupComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel22))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(settingsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel24)
                    .add(userAgentTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 39, Short.MAX_VALUE)
                .add(proxyActiveCheckBox)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(settingsDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(cancelSettingsButton)
                    .add(okSettingsButton))
                .addContainerGap())
        );

        jTipsTricksDialog.setTitle("Tips and Tricks");
        jTipsTricksDialog.setMinimumSize(new java.awt.Dimension(540, 370));

        jTipsTricksEditorPane.setContentType("text/html");
        jTipsTricksEditorPane.setEditable(false);
        jScrollPane6.setViewportView(jTipsTricksEditorPane);

        jOkTipsTricks.setText("Ok");
        jOkTipsTricks.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jOkTipsTricksActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jTipsTricksDialogLayout = new org.jdesktop.layout.GroupLayout(jTipsTricksDialog.getContentPane());
        jTipsTricksDialog.getContentPane().setLayout(jTipsTricksDialogLayout);
        jTipsTricksDialogLayout.setHorizontalGroup(
            jTipsTricksDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jTipsTricksDialogLayout.createSequentialGroup()
                .addContainerGap()
                .add(jTipsTricksDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 672, Short.MAX_VALUE)
                    .add(jOkTipsTricks))
                .addContainerGap())
        );
        jTipsTricksDialogLayout.setVerticalGroup(
            jTipsTricksDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jTipsTricksDialogLayout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jOkTipsTricks)
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SMF Backup");
        setIconImage(getSMFBackupAppIcon());
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowDeactivated(java.awt.event.WindowEvent evt) {
                formWindowDeactivated(evt);
            }
            public void windowIconified(java.awt.event.WindowEvent evt) {
                formWindowIconified(evt);
            }
        });

        manageForumsButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/manage_forums.png"))); // NOI18N
        manageForumsButton.setToolTipText("Manage Forums...");
        manageForumsButton.setBorderPainted(false);
        manageForumsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                manageForumsButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(manageForumsButton);

        lookAndFeelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/images.png"))); // NOI18N
        lookAndFeelButton.setToolTipText("Look And Feel");
        lookAndFeelButton.setBorderPainted(false);
        lookAndFeelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lookAndFeelButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(lookAndFeelButton);

        settingsButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/wrench.png"))); // NOI18N
        settingsButton.setToolTipText("Settings");
        settingsButton.setBorderPainted(false);
        settingsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                settingsButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(settingsButton);

        stopAllBackupsButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/stop.png"))); // NOI18N
        stopAllBackupsButton.setToolTipText("Stop all running backups.");
        stopAllBackupsButton.setBorderPainted(false);
        stopAllBackupsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopAllBackupsButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(stopAllBackupsButton);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.NORTH);

        displaySplitPane.setDividerLocation(150);
        displaySplitPane.setContinuousLayout(true);
        displaySplitPane.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                displaySplitPanePropertyChange(evt);
            }
        });

        jScrollPane3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        forumsTree.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                forumsTreeMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                forumsTreeMouseReleased(evt);
            }
        });
        forumsTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                forumsTreeValueChanged(evt);
            }
        });
        jScrollPane3.setViewportView(forumsTree);

        displaySplitPane.setLeftComponent(jScrollPane3);

        jScrollPane5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jScrollPane5.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        logTextArea.setColumns(20);
        logTextArea.setEditable(false);
        logTextArea.setFont(new java.awt.Font("Tahoma", 0, 12));
        logTextArea.setRows(5);
        jScrollPane5.setViewportView(logTextArea);

        displaySplitPane.setRightComponent(jScrollPane5);

        getContentPane().add(displaySplitPane, java.awt.BorderLayout.CENTER);

        jStatusBar.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jStatusBar.setFloatable(false);
        jStatusBar.setRollover(true);

        jStatusLabel.setText(" ");
        jStatusBar.add(jStatusLabel);

        getContentPane().add(jStatusBar, java.awt.BorderLayout.SOUTH);

        jMenu1.setMnemonic('F');
        jMenu1.setText("File");

        exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.ALT_MASK));
        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(exitMenuItem);

        jMenuBar1.add(jMenu1);

        jMenu3.setMnemonic('o');
        jMenu3.setText("Forums");

        manageForumsMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/manage_forums.png"))); // NOI18N
        manageForumsMenuItem.setMnemonic('M');
        manageForumsMenuItem.setText("Manage Forums...");
        manageForumsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                manageForumsMenuItemActionPerformed(evt);
            }
        });
        jMenu3.add(manageForumsMenuItem);

        lookandfeelMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/images.png"))); // NOI18N
        lookandfeelMenuItem.setMnemonic('L');
        lookandfeelMenuItem.setText("Look and Feel...");
        lookandfeelMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lookandfeelMenuItemActionPerformed(evt);
            }
        });
        jMenu3.add(lookandfeelMenuItem);

        settingsMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/wrench.png"))); // NOI18N
        settingsMenuItem.setMnemonic('S');
        settingsMenuItem.setText("Settings...");
        settingsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                settingsMenuItemActionPerformed(evt);
            }
        });
        jMenu3.add(settingsMenuItem);

        jMenuBar1.add(jMenu3);

        jMenu2.setMnemonic('H');
        jMenu2.setText("Help");

        jTipsTricksMenuItem.setText("Tips & Tricks");
        jTipsTricksMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTipsTricksMenuItemActionPerformed(evt);
            }
        });
        jMenu2.add(jTipsTricksMenuItem);

        jChangeLogMenuItem.setText("Change Log");
        jChangeLogMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jChangeLogMenuItemActionPerformed(evt);
            }
        });
        jMenu2.add(jChangeLogMenuItem);
        jMenu2.add(jSeparator2);

        aboutMenuItem.setMnemonic('A');
        aboutMenuItem.setText("About...");
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        jMenu2.add(aboutMenuItem);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void displaySplitPanePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_displaySplitPanePropertyChange
        Configuration.setDividerLocation(((JSplitPane) evt.getSource()).getDividerLocation() + "");
    }//GEN-LAST:event_displaySplitPanePropertyChange

    private void formWindowIconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowIconified
        if (isWindows) {
            setVisible(false);
        }
    }//GEN-LAST:event_formWindowIconified

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        if (lastDialogOnScreen != null) {
            lastDialogOnScreen.toFront();
        }
    }//GEN-LAST:event_formWindowActivated

    private void formWindowDeactivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowDeactivated
        lastDialogOnScreen = evt.getOppositeWindow();
    }//GEN-LAST:event_formWindowDeactivated

    private void forumsTreeMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_forumsTreeMousePressed
        if (evt.isPopupTrigger()) {
            Point p = MouseInfo.getPointerInfo().getLocation();
            SwingUtilities.convertPointFromScreen(p, forumsTree);
            TreePath path = forumsTree.getPathForLocation(p.x, p.y);

            if (path != null) {

                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();

                /* right click on the root ? */
                if (!(node.getUserObject() instanceof Forum)) {
                    return;
                }
                forumsTree.setSelectionPath(path);
                forumsPopupMenu.show((JComponent) evt.getSource(), evt.getX(), evt.getY());
            }
        }
    }//GEN-LAST:event_forumsTreeMousePressed

    private void stopAllBackupsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopAllBackupsButtonActionPerformed
        sch.stopAllForums();
    }//GEN-LAST:event_stopAllBackupsButtonActionPerformed

    private void lookAndFeelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lookAndFeelButtonActionPerformed
        fireLookAndFeelDialog();
    }//GEN-LAST:event_lookAndFeelButtonActionPerformed

    private void settingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsButtonActionPerformed
        fireSettingsDialog();
    }//GEN-LAST:event_settingsButtonActionPerformed

    private void manageForumsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manageForumsButtonActionPerformed
        fireManageForumsDialog();
    }//GEN-LAST:event_manageForumsButtonActionPerformed

    private void fireLookAndFeelDialog() {
        lookAndFeelDialog.pack();
        Utils.centerDialogInParent(this, lookAndFeelDialog);
        lookAndFeelDialog.setVisible(true);
    }

    private void stopBackupNowMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopBackupNowMenuItemActionPerformed
        Forum f = (Forum) ((DefaultMutableTreeNode) forumsTree.getSelectionPath().getLastPathComponent()).getUserObject();

        sch.stopForum(f);
    }//GEN-LAST:event_stopBackupNowMenuItemActionPerformed

    private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed

        JFileChooser fc = new JFileChooser(Configuration.getBackupDir());
        fc.setDialogTitle("Please select the directory where SMF Backup will save the backup files.");
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fc.showOpenDialog(settingsDialog);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            backupDirectoryTextField.setText(fc.getSelectedFile().getAbsolutePath());
        }
    }//GEN-LAST:event_browseButtonActionPerformed

    private void runBackupNowMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runBackupNowMenuItemActionPerformed
        Forum f = (Forum) ((DefaultMutableTreeNode) forumsTree.getSelectionPath().getLastPathComponent()).getUserObject();

        sch.runForum(f);
    }//GEN-LAST:event_runBackupNowMenuItemActionPerformed

    /*
     * Returns the forum position in the tree/list
     */
    private int getForumPosition(Forum f) {
        for (int i = 0; i < Configuration.getForumsDefined().size(); i++) {
            if (Configuration.getForumsDefined().elementAt(i).equals(f)) {
                return i;
            }
        }
        return -1;
    }

    private void manageForumMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manageForumMenuItemActionPerformed

        DefaultMutableTreeNode node = (DefaultMutableTreeNode) forumsTree.getSelectionPath().getLastPathComponent();

        Forum f = (Forum) node.getUserObject();
        selectForumInList(getForumPosition(f));

        fireManageForumsDialog();
    }//GEN-LAST:event_manageForumMenuItemActionPerformed

    private void proxyActiveCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_proxyActiveCheckBoxItemStateChanged
        if (evt.getStateChange() == ItemEvent.DESELECTED) {
            proxyServerNameTextField.setEnabled(false);
            proxyServerPortTextField.setEnabled(false);
        }

        if (evt.getStateChange() == ItemEvent.SELECTED) {
            proxyServerNameTextField.setEnabled(true);
            proxyServerPortTextField.setEnabled(true);
        }

    }//GEN-LAST:event_proxyActiveCheckBoxItemStateChanged

    private void okSettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okSettingsButtonActionPerformed

        Configuration.setBackupDir(backupDirectoryTextField.getText());
        Configuration.setLoggingLevel((String) loggingLevelComboBox.getSelectedItem());

        // update the logging level.
        Main.setLoggingLevel(Configuration.getLoggingLevel());
        Configuration.setStartupOption(startupComboBox.getSelectedItem().toString());

        if (proxyActiveCheckBox.isSelected()) {
            Configuration.setProxyEnabled(true);
            Configuration.setProxyPort(proxyServerPortTextField.getText());
            Configuration.setProxyHost(proxyServerNameTextField.getText());
        } else {
            Configuration.setProxyEnabled(false);
        }
        Configuration.setUserAgent(userAgentTextField.getText());
        Configuration.saveConfiguration();

        settingsDialog.setVisible(false);
    }//GEN-LAST:event_okSettingsButtonActionPerformed

    private void cancelSettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelSettingsButtonActionPerformed
        settingsDialog.setVisible(false);
    }//GEN-LAST:event_cancelSettingsButtonActionPerformed

    private void fireSettingsDialog() {
        proxyActiveCheckBox.setSelected(Configuration.isProxyEnabled());
        proxyServerNameTextField.setText(Configuration.getProxyHost());
        proxyServerPortTextField.setText(Configuration.getProxyPort());
        if ("Debug".equals(Configuration.getLoggingLevel())) {
            loggingLevelComboBox.setSelectedItem("Debug");
        }
        if ("Only Severe".equals(Configuration.getLoggingLevel())) {
            loggingLevelComboBox.setSelectedItem("Only Severe");
        }
        backupDirectoryTextField.setText(Configuration.getBackupDir());

        if (!Configuration.isProxyEnabled()) {
            proxyServerNameTextField.setEnabled(false);
            proxyServerPortTextField.setEnabled(false);
        }

        userAgentTextField.setText(Configuration.getUserAgent());

        if (Configuration.getStartupOption() != null && Configuration.getStartupOption().toLowerCase().startsWith("minimized")) {
            startupComboBox.setSelectedIndex(1);
        }

        settingsDialog.pack();
        Utils.centerDialogInParent(this, settingsDialog);

        settingsDialog.setVisible(true);
    }

    private void settingsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsMenuItemActionPerformed
        fireSettingsDialog();
    }//GEN-LAST:event_settingsMenuItemActionPerformed

    private void forumsTreeMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_forumsTreeMouseReleased
        if (evt.isPopupTrigger()) {
            Point p = MouseInfo.getPointerInfo().getLocation();
            SwingUtilities.convertPointFromScreen(p, forumsTree);
            TreePath path = forumsTree.getPathForLocation(p.x, p.y);

            if (path != null) {

                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();

                /* right click on the root ? */
                if (!(node.getUserObject() instanceof Forum)) {
                    return;
                }
                forumsTree.setSelectionPath(path);
                forumsPopupMenu.show((JComponent) evt.getSource(), evt.getX(), evt.getY());
            }
        }
    }//GEN-LAST:event_forumsTreeMouseReleased

    private void forumsTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_forumsTreeValueChanged
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) evt.getPath().getLastPathComponent();
        logTextArea.setText("");

        updateLogWindow(node);
        updateStatusLabel(node);
    }//GEN-LAST:event_forumsTreeValueChanged

    class Updater implements Runnable {

        JTextArea t;
        Forum f;

        public Updater(JTextArea textArea, Forum f) {
            this.t = textArea;
            this.f = f;
        }

        public void run() {
            t.append(f.getStatus(t.getLineCount()));
        }
    }

    class StatusBarUpdater implements Runnable {

        JLabel l;
        Forum f;

        public StatusBarUpdater(JLabel statusLabel, Forum f) {
            this.l = statusLabel;
            this.f = f;
        }

        public void run() {
            if (f.getDownloadCount() > 0) {
                l.setText("Downloaded: " + Utils.getLongAsKilo(f.getDownloadCount()));
            } else {
                l.setText(" ");
            }
        }
    }

    private void updateLogWindow(DefaultMutableTreeNode node) {
        if (ifIsRoot(node)) {
            log.debug("seems node is root, what log to update ?");
            return;
        }

        Forum f = (Forum) node.getUserObject();
        SwingUtilities.invokeLater(new Updater(logTextArea, f));
    }

    private void updateStatusLabel(DefaultMutableTreeNode node) {
        if (ifIsRoot(node)) {
            return;
        }
        Forum f = (Forum) node.getUserObject();
        SwingUtilities.invokeLater(new StatusBarUpdater(jStatusLabel, f));
    }

    private boolean ifIsRoot(DefaultMutableTreeNode node) {
        return node.getUserObject().equals(rootName);
    }

    public void fireLogUpdate() {

        if (forumsTree.getSelectionPath() == null) {
            log.debug("Selection path is null, don't know what window to update.");
            return;
        }
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) forumsTree.getSelectionPath().getLastPathComponent();

        updateLogWindow(node);
        updateStatusLabel(node);
    }

    private void cancelChangeLFButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelChangeLFButtonActionPerformed
        lookAndFeelDialog.setVisible(false);
    }//GEN-LAST:event_cancelChangeLFButtonActionPerformed

    private void okChangeLFButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okChangeLFButtonActionPerformed

        try {
            propagateUIChanges(lf[lookAndFeelComboBox.getSelectedIndex()].getClassName());

            Configuration.setLookAndFeel(lf[lookAndFeelComboBox.getSelectedIndex()].getClassName());
            lookAndFeelDialog.setVisible(false);
            Configuration.saveConfiguration();
        } catch (Throwable cnfe) {
            ErrorHandler.showError("Unable to apply/save configuration.", cnfe);
        }
    }//GEN-LAST:event_okChangeLFButtonActionPerformed

    private void lookandfeelMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lookandfeelMenuItemActionPerformed
        fireLookAndFeelDialog();
    }//GEN-LAST:event_lookandfeelMenuItemActionPerformed

    private void closeAboutDialogButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeAboutDialogButtonActionPerformed
        aboutDialog.setVisible(false);
    }//GEN-LAST:event_closeAboutDialogButtonActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        aboutDialog.pack();
        Utils.centerDialogInParent(this, aboutDialog);
        aboutDialog.setVisible(true);
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void removeForumButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeForumButtonActionPerformed
        Forum f = (Forum) forumsDefinedList.getSelectedValue();

        Configuration.removeForum(f);
        repopulateForumsList(Configuration.getForumsDefined().size() - 1);
        if (Configuration.getForumsDefined().size() == 0) {
            setEnabledStateOfManageForumsDialog(false);
        }
    }//GEN-LAST:event_removeForumButtonActionPerformed

    private void repopulateForumsList(int whichOne) {
        forumsDefinedList.setListData(Configuration.getForumsDefined());

        // this will trigger an event which will fill out the values
        selectForumInList(whichOne);
    }

    private void forumsDefinedListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_forumsDefinedListMouseClicked
        if (evt.getClickCount() == 1) {
            selectForumInList(forumsDefinedList.getSelectedIndex());
            evt.consume();
        }
    }//GEN-LAST:event_forumsDefinedListMouseClicked

    private void updateForumButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateForumButtonActionPerformed
        Forum f = (Forum) forumsDefinedList.getSelectedValue();

        f.setName(forumNameTextField.getText());

        String url = forumURLTextField.getText();
        f.setUrl(url);

        f.setUsername(forumAdminUserNameTextField.getText());
        f.setVersion(forumVersionDropDown.getSelectedIndex());
        f.setPass(new String(forumAdminPasswordTextField.getPassword()));
        if (intervalComboBox.getSelectedIndex() == 0) {
            f.setInterval("daily");
        }
        f.setRepeatEvery(((Integer) repeatAtJSpinner.getValue()).toString());
        f.setStartAt(Utils.getHourAsString((Date) startAtJSpinner.getModel().getValue()));
        f.setDisableBackups(forumDisableBackupCheckBox.isSelected());
        f.setDoBackupWhenForumStarts(forumDoBackupAtStartCheckBox.isSelected());
        f.setDoCompression(forumDoCompression.isSelected());

        Configuration.setConfigurationChanged();

        forumsDefinedList.repaint();

    }//GEN-LAST:event_updateForumButtonActionPerformed

    private Image getSMFBackupAppIcon() {
        URL link = MainWindow.class.getResource("/img/AppIconSmall.gif");
        Image icon = Toolkit.getDefaultToolkit().getImage(link);

        return icon;
    }

    private void addNewForumButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addNewForumButtonActionPerformed
        addNewForum();

        setEnabledStateOfManageForumsDialog(true);
    }//GEN-LAST:event_addNewForumButtonActionPerformed

    public void addNewForum() {
        Configuration.addNewForum();

        Vector forums = Configuration.getForumsDefined();
        forumsDefinedList.setListData(forums);

        // this will trigger an event which will fill out the values
        selectForumInList(forums.size() - 1);
    }

    public void selectForumInList(int whichOne) {

        if (whichOne < 0 || Configuration.getForumsDefined().size() == 0) {
            return;
        }
        Forum f = (Forum) Configuration.getForumsDefined().elementAt(whichOne);
        forumNameTextField.setText(f.getName());
        forumURLTextField.setText(f.getUrl());
        forumAdminUserNameTextField.setText(f.getUsername());
        forumAdminPasswordTextField.setText(f.getPass());

        forumVersionDropDown.setSelectedIndex(f.getVersion());
        if ("daily".equals(f.getInterval())) {
            intervalComboBox.setSelectedIndex(0);
        }
        startAtJSpinner.getModel().setValue(Utils.createDateFromString(f.getStartAt()));
        repeatAtJSpinner.getModel().setValue(Integer.decode(f.getRepeatEvery()));

        forumDoBackupAtStartCheckBox.setSelected(f.isDoBackupWhenForumStarts());
        forumDisableBackupCheckBox.setSelected(f.isDisableBackups());
        forumDoCompression.setSelected(f.isDoCompression());

        forumsDefinedList.setSelectedIndex(whichOne);

    }

    private void clickOnForum(int whichone) {
        if (whichone < 0 || whichone >= Configuration.getForumsDefined().size()) {
            return;
        }
        forumsTree.setSelectionRow(whichone + 1);
    }

    private void closeManageForumsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeManageForumsButtonActionPerformed

        int answer = askSaveConfig();

        if (answer == JOptionPane.CANCEL_OPTION || answer == JOptionPane.CLOSED_OPTION) {
            return;
        }
        if (answer == JOptionPane.YES_OPTION) {
            Configuration.saveConfiguration();
            sch.reloadConfig();
        }
        if (answer == JOptionPane.NO_OPTION) {
            Configuration.restoreSettings();
        }
        repopulateForumsTree();
        clickOnForum(0);

        manageForumsDialog.setVisible(false);

    }//GEN-LAST:event_closeManageForumsButtonActionPerformed

    public int askSaveConfig() {
        if (Configuration.isConfigurationChanged()) {
            return JOptionPane.showConfirmDialog(manageForumsDialog, "Do you want to save your changes ?", "Configuration changed", JOptionPane.YES_NO_CANCEL_OPTION);
        } else {
            return JOptionPane.NO_OPTION;
        }
    }

    private void setEnabledStateOfManageForumsDialog(boolean newstate) {
        removeForumButton.setEnabled(newstate);
        updateForumButton.setEnabled(newstate);

        forumNameTextField.setEnabled(newstate);
        forumURLTextField.setEnabled(newstate);
        forumAdminPasswordTextField.setEnabled(newstate);
        forumAdminUserNameTextField.setEnabled(newstate);
        forumVersionDropDown.setEnabled(newstate);
        intervalComboBox.setEnabled(newstate);
        startAtJSpinner.setEnabled(newstate);
        repeatAtJSpinner.setEnabled(newstate);

        forumDoBackupAtStartCheckBox.setEnabled(newstate);
        forumDisableBackupCheckBox.setEnabled(newstate);

        if (newstate == false) {
            forumNameTextField.setText("");
            forumURLTextField.setText("");
            forumAdminPasswordTextField.setText("");
            forumAdminUserNameTextField.setText("");

        }

    }

    private void fireManageForumsDialog() {
        final JFrame parent = this;
        Configuration.backupSettings();

        // invalidate the dialog if no forum (force the user to choose a forum)
        if (Configuration.getForumsDefined().size() == 0) {
            setEnabledStateOfManageForumsDialog(false);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                manageForumsDialog.pack();
                Utils.centerDialogInParent(parent, manageForumsDialog);
                manageForumsDialog.setVisible(true);
            }
        });
    }

    private void manageForumsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manageForumsMenuItemActionPerformed
        repopulateForumsList(0);
        fireManageForumsDialog();
    }//GEN-LAST:event_manageForumsMenuItemActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        Utils.exitApplication(sch);
    }//GEN-LAST:event_formWindowClosed

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        Utils.exitApplication(sch);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void jOkTipsTricksActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jOkTipsTricksActionPerformed
        jTipsTricksDialog.setVisible(false);
    }//GEN-LAST:event_jOkTipsTricksActionPerformed

    private void jTipsTricksMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTipsTricksMenuItemActionPerformed
        displayHtmlWindow("Tips And Tricks", "/img/tipstricks.html");
    }//GEN-LAST:event_jTipsTricksMenuItemActionPerformed

    private void displayHtmlWindow(String title, String contentResourcePath) {
        try {
            jTipsTricksDialog.setTitle(title);
            jTipsTricksEditorPane.setPage(MainWindow.class.getResource(contentResourcePath));
            Utils.centerDialogInParent(this, jTipsTricksDialog);
            jTipsTricksDialog.setVisible(true);
        } catch (IOException ioe) {
            log.error("Unable to display " + title + " page.", ioe);
        }
    }

    private void jChangeLogMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jChangeLogMenuItemActionPerformed
        displayHtmlWindow("Change Log", "/img/changelog.html");
    }//GEN-LAST:event_jChangeLogMenuItemActionPerformed

    private void jVisitHomePageActionPerformed(java.awt.event.ActionEvent evt) {
        try {
            Desktop.getDesktop().browse(new URI("http://hex.ro/wb/pages/projects/java-smf-backup-2.php"));
        } catch (Throwable ex) {
            ErrorHandler.showError("Unable to connect to application home page.", ex);
        }
    }

    public void actionPerformed(ActionEvent e) {
        // ? left click on icon
        if (e.getActionCommand() == null) {
            if (isVisible()) {
                setState(Frame.ICONIFIED);
                setVisible(false);
            } else {
                setVisible(true);
                setState(Frame.NORMAL);
            }
        } else if (e.getActionCommand().equals("Show Window")) {
            setVisible(true);
            this.setState(Frame.NORMAL);
        } else if (e.getActionCommand().equals("Quit")) {
            Utils.exitApplication(sch);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog aboutDialog;
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JTextArea ackTextArea;
    private javax.swing.JButton addNewForumButton;
    private javax.swing.JTextField backupDirectoryTextField;
    private javax.swing.JButton browseButton;
    private javax.swing.JButton cancelChangeLFButton;
    private javax.swing.JButton cancelSettingsButton;
    private javax.swing.JButton closeAboutDialogButton;
    private javax.swing.JButton closeManageForumsButton;
    private javax.swing.JSplitPane displaySplitPane;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JPasswordField forumAdminPasswordTextField;
    private javax.swing.JTextField forumAdminUserNameTextField;
    private javax.swing.JCheckBox forumDisableBackupCheckBox;
    private javax.swing.JCheckBox forumDoBackupAtStartCheckBox;
    private javax.swing.JCheckBox forumDoCompression;
    private javax.swing.JTextField forumNameTextField;
    private javax.swing.JTextField forumURLTextField;
    private javax.swing.JComboBox forumVersionDropDown;
    private javax.swing.JList forumsDefinedList;
    private javax.swing.JPopupMenu forumsPopupMenu;
    private javax.swing.JTree forumsTree;
    private javax.swing.JComboBox intervalComboBox;
    private javax.swing.JMenuItem jChangeLogMenuItem;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JButton jOkTipsTricks;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JToolBar jStatusBar;
    private javax.swing.JLabel jStatusLabel;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JDialog jTipsTricksDialog;
    private javax.swing.JEditorPane jTipsTricksEditorPane;
    private javax.swing.JMenuItem jTipsTricksMenuItem;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton jVisitHomePage;
    private javax.swing.JTextArea logTextArea;
    private javax.swing.JComboBox loggingLevelComboBox;
    private javax.swing.JButton lookAndFeelButton;
    private javax.swing.JComboBox lookAndFeelComboBox;
    private javax.swing.JDialog lookAndFeelDialog;
    private javax.swing.JMenuItem lookandfeelMenuItem;
    private javax.swing.JMenuItem manageForumMenuItem;
    private javax.swing.JButton manageForumsButton;
    private javax.swing.JDialog manageForumsDialog;
    private javax.swing.JMenuItem manageForumsMenuItem;
    private javax.swing.JButton okChangeLFButton;
    private javax.swing.JButton okSettingsButton;
    private javax.swing.JCheckBox proxyActiveCheckBox;
    private javax.swing.JTextField proxyServerNameTextField;
    private javax.swing.JTextField proxyServerPortTextField;
    private javax.swing.JButton removeForumButton;
    private javax.swing.JSpinner repeatAtJSpinner;
    private javax.swing.JMenuItem runBackupNowMenuItem;
    private javax.swing.JButton settingsButton;
    private javax.swing.JDialog settingsDialog;
    private javax.swing.JMenuItem settingsMenuItem;
    private javax.swing.JSpinner startAtJSpinner;
    private javax.swing.JComboBox startupComboBox;
    private javax.swing.JButton stopAllBackupsButton;
    private javax.swing.JMenuItem stopBackupNowMenuItem;
    private javax.swing.JButton updateForumButton;
    private javax.swing.JTextField userAgentTextField;
    private javax.swing.JLabel versionLabel;
    // End of variables declaration//GEN-END:variables
}
